﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;

namespace ChatServer
{
    
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class ChatService : IChatService
    {
        private model.ServerSocket ss;

        public ChatService()
        {
            ss = new model.ServerSocket();
        }

        public bool Login(string UserName, string ipAddress, string Password)
        {
            OperationContext context = OperationContext.Current;
            MessageProperties messageProperties = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpointProperty = 
                messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

            return ss.Login(UserName, ipAddress, Password);
        }

        public void SendMessage(string xml)
        {
            ss.SendMessage(xml);
        }

        public void LogOut(string IPAddress)
        {
            ss.LogOut(IPAddress);
        }
    }
}
